<template>
  <base-container>
    <!-- http://localhost:8070/dev-api/assets-ms/file/upload?fileType=2&isSecretFile=true -->
    <div>
      <base-upload
        action="#"
        :mode="'upload'"
        :drag="false"
        :limit="5"
        :is-upload-mode="true"
        list-type="picture-card"
        :on-success="handleSuccess"
        :on-error="handleError"
        v-model:file-list="fileList"
        :http-request="customUpload"
        :show-file-list="true"
      >
        <el-button type="primary">选择文件</el-button>
      </base-upload>
    </div>

    <!-- <el-button type="primary">选择文件</el-button> -->
  </base-container>
</template>

<script setup>
  import { commonUpload } from "@/api/model/files.js";
  const route = useRoute();
  const fileList = ref([]);

  const handleSuccess = (response, file, fileList) => {
    console.log("上传成功", response);
  };

  const customUpload = options => {
    let { file } = options;
    // console.log(options,"options")
    const formData = new FormData();
    formData.append("file", file);
    console.log(file);
    commonUpload(formData, { fileType: 2, isSecretFile: true }).then(res => {
      if (res.code == 200) {
        console.log(res.data);
        file.url = res.data;
        console.log(fileList.value, "fileList");
      }
    });
  };

  const handleError = (error, file, fileList) => {
    console.error("上传失败", error);
  };
</script>
<style lang="scss" scoped></style>
